package com.billion.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 定义机组rabbit队列对应关系
 */
@Configuration
public class WaterConfig {

    /**
     * 声明水表交换机
     * @return
     */
    @Bean
    public static DirectExchange waterExchange() {
        return new DirectExchange("water_exchange");
    }

    /**
     * 声明4G水表队列
     *
     * @return
     */
    @Bean
    public Queue jobWater4GQueue(){
        return new Queue("job_water_4G_queue");
    }

    /**
     * 声明NB水表队列
     *
     * @return
     */
    @Bean
    public Queue jobWaterNBQueue(){
        return new Queue("job_water_NB_queue");
    }

    /**
     * 声明AEP水表队列
     *
     * @return
     */
    @Bean
    public Queue jobWaterAEPQueue(){
        return new Queue("job_water_AEP_queue");
    }

    /**
     * 声明4G水表抄表返回队列
     *
     * @return
     */
    @Bean
    public Queue resultWater4GQueue(){
        return new Queue("result_water_4G_queue");
    }

    /**
     * 声明NB水表抄表返回队列
     *
     * @return
     */
    @Bean
    public Queue resultWaterNBQueue(){
        return new Queue("result_water_NB_queue");
    }

    /**
     * 声明AEP水表抄表返回队列
     *
     * @return
     */
    @Bean
    public Queue resultWaterAEPQueue(){
        return new Queue("result_water_AEP_queue");
    }

    /**
     * 将4G水表抄表队列绑定路由
     * @return
     */
    @Bean
    public Binding jobWater4GDirectBindExchange() {
        return BindingBuilder.bind(jobWater4GQueue()).to(waterExchange()).with("job_4G");
    }

    /**
     * 将NB电表抄表队列绑定路由
     * @return
     */
    @Bean
    public Binding jobWaterNBDirectBindExchange() {
        return BindingBuilder.bind(jobWaterNBQueue()).to(waterExchange()).with("job_NB");
    }

    /**
     * 将AEP电表抄表队列绑定路由
     * @return
     */
    @Bean
    public Binding jobWaterAEPDirectBindExchange() {
        return BindingBuilder.bind(jobWaterAEPQueue()).to(waterExchange()).with("job_AEP");
    }

    /**
     * 将4G电表抄表结果绑定路由
     * @return
     */
    @Bean
    public Binding resultWater4GDirectBindExchange() {
        return BindingBuilder.bind(resultWater4GQueue()).to(waterExchange()).with("result_4G");
    }

    /**
     * 将NB电表抄表结果绑定路由
     * @return
     */
    @Bean
    public Binding resultWaterNBDirectBindExchange() {
        return BindingBuilder.bind(resultWaterNBQueue()).to(waterExchange()).with("result_NB");
    }

    /**
     * 将AEP电表抄表结果绑定路由
     * @return
     */
    @Bean
    public Binding resultWaterAEPDirectBindExchange() {
        return BindingBuilder.bind(resultWaterAEPQueue()).to(waterExchange()).with("result_AEP");
    }
}